home *** CD-ROM | disk | FTP | other *** search
- Path: crchh327.rich.bnr.ca!jobell
- From: jobell@bnr.ca (Bret Bieghler)
- Newsgroups: comp.lang.c++
- Subject: Creating an object via new with ONLY a pointer to the object
- Date: 10 Apr 1996 18:55:59 GMT
- Organization: Bell-Northern Research Ltd.
- Message-ID: <4kh07v$lno@crchh327.rich.bnr.ca>
- NNTP-Posting-Host: crchhd4a.rich.bnr.ca
-
- An interesting problem I've come across... I was wondering if this
- is possible:
-
- I have a generic CommandObject which defines several pure virtual
- functions. Derived from CommandObject are user commands, such
- as ExitCommand, StatusCommand, etc.
-
- To process a command (currently) I do the following:
-
- CommandObject* basePtr;
-
- if (command == "exit")
- {
- basePtr = new ExitCommand;
- basePtr->implement();
- }
- else if (command == "status")
- {
- basePtr = new StatusCommand;
- basePtr->implement();
- }
-
- What I would LIKE to do is the the following:
-
- CommandObject* basePtr = new commandTable[command];
-
- where commandTable is an associative array as follows:
-
- Key Value
- "exit" ExitCommand*
- "status" StatusCommand*
-
- The problem is if there is a way to create a new object
- of a given type having only a pointer to that type.
-
- Is this possible?
-
- Regards,
-
- Joe
- --
- Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
- Northern Telecom / Bell-Northern Research
- "What? Evacuate now, in our moment of triumph? Surely you overestimate their chances."
-